

export function timeFix() {
    const time = new Date();
    const hour = time.getHours();
    return hour < 9 ? '早上好' : (hour <= 11 ? '上午好' : (hour <= 13 ? '中午好' : (hour < 20 ? '下午好' : '晚上好')))
}

// 生成首页路由
export function generateIndexRouter(data) {
    let indexRouter = [{
              path: '/',
              name: 'dashboard',
              redirect: '/user/login',
              component: resolve => require(['@/common/components/layouts/TabLayout'], resolve),
              meta: { title: '首页' },
              children: [
                ...generateChildRouters(data)
              ]
            },{
              "path": "*", "redirect": "/404", "hidden": true
            }]
      return indexRouter;
}

// 生成子路由
function generateChildRouters(data) { 
    const routers = [];
    for (let item of data) {
      let component = "";
      if(item.component.indexOf("layouts")>=0){
         component = "common/components/"+item.component;
      }else{
         component = "modules/"+item.component+"/"+item.meta.componentName;
      }
      let menu = {
        path: item.path,
        name: item.name,
        redirect: item.redirect,
        component:resolve => require(['@/' + component+'.vue'], resolve),
        hidden: false,
        meta: {
          title: item.meta.title,
          icon: item.meta.icon,
          url: item.meta.url,
          permissionList: item.meta.permissionList,
          keepAlive: item.meta.keepAlive,
          internalOrExternal:item.meta.internalOrExternal,
          componentName:item.meta.componentName
        }
      }
      if(item.alwaysShow){
        menu.alwaysShow = true;
        menu.redirect = menu.path;
      }
      // 递归
      if(item.children && item.children.length > 0) {
        menu.children = [...generateChildRouters(item.children)]
      }
      // 判断是否生成路由
      if(item.route && item.route === '0') {
        console.log('AAAAAAAAAA');
      }else {
        routers.push(menu);
      }
    }
    return routers;
}

export function triggerWindowResizeEvent() {
    let event = document.createEvent('HTMLEvents')
    event.initEvent('resize', true, true)
    event.eventType = 'message'
    window.dispatchEvent(event)
}

/**
 * 过滤对象为空的属性
 * @param {*} obj 
 */
export function filterObj(obj) { 
  if (!(typeof obj == 'object')) { 
    return;
  }
  for (let key in obj) { 
    if (Object.prototype.hasOwnProperty.call(obj,key)
      && (obj[key] == null || obj[key] == undefined || obj[key] === '')
    ) { 
      delete obj[key];
    }
  }
  return obj;
}
  